<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - reference_counter.cpp</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2006  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font>

<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>sstream<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>string<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>cstdlib<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>ctime<font color='#5555FF'>&gt;</font>

<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>dlib<font color='#5555FF'>/</font>reference_counter.h<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='tester.h.html'>tester.h</a>"

<font color='#0000FF'>namespace</font>  
<b>{</b>

    <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> test;
    <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> std;
    <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> dlib;

    logger <b><a name='dlog'></a>dlog</b><font face='Lucida Console'>(</font>"<font color='#CC0000'>test.reference_counter</font>"<font face='Lucida Console'>)</font>;

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> ref_counter 
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='reference_counter_test'></a>reference_counter_test</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <font color='#009900'>/*!
        requires
            - ref_counter is an implementation of reference_counter/reference_counter_kernel_abstract.h 
              and is instantiated to contain an int 
        ensures
            - runs tests on reference_counter for compliance with the specs 
    !*/</font>
    <b>{</b>        

        ref_counter a, b, c;

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> <font color='#979000'>10</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>print_spinner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> <font color='#979000'>10000</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                a.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> j;
                b.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>1</font>;
                c.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>b.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>1</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>c.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>b.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>1</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>c.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>b.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>1</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>c.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>b.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>1</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>c.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                a <font color='#5555FF'>=</font> c;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>b.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>1</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>c.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>b.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>1</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>c.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>b.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>1</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>c.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>b.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>1</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>c.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;

                a <font color='#5555FF'>=</font> b <font color='#5555FF'>=</font> c;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> b.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> c.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>c.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> b.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                a.<font color='#BB00BB'>modify</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> j;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> b.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> c.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>c.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> b.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>c.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>b.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;

                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                a <font color='#5555FF'>=</font> a;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                c <font color='#5555FF'>=</font> c;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>c.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>b.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>a,c<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>c.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>b.<font color='#BB00BB'>access</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> j<font color='#5555FF'>+</font><font color='#979000'>2</font>,"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

    <b>}</b>





    <font color='#0000FF'>class</font> <b><a name='reference_counter_tester'></a>reference_counter_tester</b> : <font color='#0000FF'>public</font> tester
    <b>{</b>
    <font color='#0000FF'>public</font>:
        <b><a name='reference_counter_tester'></a>reference_counter_tester</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> :
            tester <font face='Lucida Console'>(</font>"<font color='#CC0000'>test_reference_counter</font>",
                    "<font color='#CC0000'>Runs tests on the reference_counter component.</font>"<font face='Lucida Console'>)</font>
        <b>{</b><b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='perform_test'></a>perform_test</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>testing kernel_1a</font>";
            reference_counter_test<font color='#5555FF'>&lt;</font>reference_counter<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>int</u></font><font color='#5555FF'>&gt;</font>::kernel_1a<font color='#5555FF'>&gt;</font>  <font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b> a;

<b>}</b>



</pre></body></html>